package com.lab.book.common.bean;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.Date;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.lab.cloud.common.converter.enums.SexEnum;
import com.lab.cloud.common.validation.group.*;

import lombok.Data;
import net.sf.jsqlparser.statement.select.First;
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;

import com.alibaba.fastjson.annotation.JSONField;
import com.lab.book.common.validation.group.LoginGroup;
import com.lab.book.common.validation.group.RegisterGroup;
import com.lab.book.common.validation.group.SearchGroup;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

@ApiModel(value = "用户实体", description = "当前数据库表信息")
@Data
public class User implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@ApiModelProperty(value = "用户ID",hidden = true)
	private Long id;
	
	@ApiModelProperty(value = "用户名")
	@Length(min = 2, max = 30, message = "{user.name}", groups = { First.class, LoginGroup.class, RegisterGroup.class })
	private String name;

	@ApiModelProperty(value = "用户密码")
	@Pattern(regexp = "^[a-z0-9A-Z]{6,16}$", message = "密码为6到16位字母...", groups = { Second.class, LoginGroup.class,
			RegisterGroup.class })
	private String password;
	
	@ApiModelProperty(value = "确认密码",hidden = true)
	@Pattern(regexp = "^[a-z0-9A-Z]{6,16}$", message = "确认密码为6到16位字母...", groups = { Third.class, RegisterGroup.class })
	@TableField(exist = false)
	private String repwd;
	
	@ApiModelProperty(value = "用户年龄")
	@NotNull(message = "年龄不能为空。", groups = { Fourth.class, RegisterGroup.class })
	@Min(value = 18, message = "{user.age}", groups = { Fourth.class, SearchGroup.class, RegisterGroup.class })
	private Integer age;
	
	@ApiModelProperty(value = "用户性别")
	@TableField("sex")
	private SexEnum sex;

	@ApiModelProperty(value = "用户邮箱")
	@Pattern(regexp = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$", message = "邮箱地址错误。", groups = {
			Fifth.class, RegisterGroup.class })
	private String email;
	
	@ApiModelProperty(value = "身份证号码")
	@NotEmpty(message = "身份证号码不能为空。")
	private String idno;
	
	@ApiModelProperty(hidden = true)
	@TableField(fill = FieldFill.INSERT)
	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
	private Date createTime;

	@ApiModelProperty(hidden = true)
	@TableField(fill = FieldFill.INSERT_UPDATE)
	@JSONField(format = "yyyy-MM-dd HH:mm:ss")
	private Date updateTime;

	@Override
	public String toString() {
		return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
	}

}
